/**
 * @class   wosh::gui::KioskManager
 * @brief   
 *
 *
 ****************************************************************************
 * @version $Id: KioskManager.h 2887 2010-08-11 08:09:41Z alex $
 * @author  Alessandro Polo
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

#ifndef __WOSH_Gui_KioskManager_H__
 #define __WOSH_Gui_KioskManager_H__

 #include <QObject>

#include <QtGui/QGraphicsRectItem>
#include <QtGui/QTabWidget>

#include <core/Containers.h>
#include <core/PropertiesProvider.h>
#include <core/MethodsProvider.h>
#include <core/BusConnector.h>
#include <core/Method.h>
#include <core/Request.h>
#include <framework/gui/IWidget.h>

#include "KioskLayout.h"
#include "KioskSecurity.h"
#include "KioskGadget.h"
#include "KioskSheet.h"


namespace wosh {
 namespace gui {


class KioskManager :	public QObject,
						public Object,
						public virtual IPropertiesProviderListener,
						public virtual IBusListener,
						protected MethodRunner,
						public virtual INavigatorListener
 {
	Q_OBJECT

	WOSH_CLASSNAME(wosh::gui::KioskManager)


	public:
		KioskManager();
		virtual ~KioskManager();

	public:
		void init();

		void logoff() {
			// WHAT if a modal dialog is shown? check
			// depends on settings
			if ( false ) { // may prompt a screensaver
				this->layout->blockInput(false);
			 }
			else {
				this->layout->showModal(this->security->getDialogLogin());
			 }
		 }

		virtual void itemSelected( NavigatorItem* item );

	public slots:
		void security_userLoggedIn() {
			this->layout->hideModal();
			refreshView();
		 }

		void security_userAuthorizationFault() {

		 }


	public:

		static bool request_sheet_maximize( bool value ) {// string:NAME ?
			KioskManager::getInstance()->layout->maximize_sheet( value );
			return true;
		 }

		static bool request_gadget_maximize( KioskGadget* item ) {// string:NAME ?
			// validate:  user is logged?
			// validate:  another item is maximized?
			// validate:  gadget has permission?

			// forward to layout
			KioskManager::getInstance()->layout->maximize( item->asQGraphicsWidget() );

			return true;
		 }
		//static bool requested_gadget_restore( KioskGadget* source ) {
		// }
		//	QObject* qObj = QObject::sender();




//@}
/** @name Setup
 * @{
 ******************************************************************************/
	public:
		void setLayout( KioskLayout* Layout );

//@}
/** @name Sheets and Gadgets
 * @{
 ******************************************************************************/
	public:
		void registerSheet( KioskSheet* item );

		void registerGadget( KioskGadget* item );

		void refreshView();

//@}
/** @name IBusListener implementation
 * @{
 ******************************************************************************/
	public:
		void busMessage( const Message& message, const Bus* source );
//@}
/** @name IPropertiesProviderListener interface
 * @{
 ******************************************************************************/
 	protected:
		bool readingProperty( Property*, const PropertiesProvider* ) { return true; }
		bool updatingProperty( bool& do_update, const Variant& value_proposed, Property& property_current, const PropertiesProvider* source );
//@}
/** @name Getters
 * @{
 ******************************************************************************/
	public:
		KioskLayout* getLayout()			{ return this->layout; }
		KioskSecurity* getSecurity()		{ return this->security; }
//@}

	protected:
		KioskSheet* getSheetByName_( const string& name );
		KioskSheet* getSheetByContext_( const string& context );

	protected:
		KioskLayout* layout;
		KioskSecurity* security;

	protected:
		ListT<KioskGadget*> gadgets;
		ListT<KioskSheet*> sheets;

	protected:
		BusConnector BusCore;
		mutable LogContext Log;

		mutable MethodsProvider Methods;
		mutable PropertiesProvider Properties;

	private:
		static KioskManager* instance;
		static KioskManager* getInstance()	{ return KioskManager::instance; }


}; // class def

  }; // namespace gui
}; // namespace wosh

#endif //__WOSH_Gui_KioskManager_H__
